<template>
  <el-dialog
    :visible.sync="dialogVisible"
    width="auto"
    class="references-dialog"
    :append-to-body="true"
    :close-on-click-modal="true"
    top="8vh"
    @close="handleClose">
    <span slot="title" class="references-dialog-title">
      <i class="el-icon-collection-tag"></i>
      引用内容
    </span>
    <div class="references-dialog-body">
      <div v-for="(resource, idx) in references" :key="idx" class="reference-item-dialog">
        <div class="reference-item-header-dialog">
          <span class="reference-num-dialog">{{ idx + 1 }}</span>
          <span class="reference-source-dialog">{{ resource.dataset_name || resource.document_name || resource.document_title || '引用来源' }}</span>
        </div>
        <div class="reference-item-content-dialog">{{ resource.content }}</div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'ReferencesDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    references: {
      type: Array,
      default: () => []
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  methods: {
    handleClose() {
      this.$emit('update:visible', false)
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>
/* 弹窗样式优化 - 使用仿宋字体，自适应内容 */
.references-dialog ::v-deep .el-dialog {
  min-width: 500px;
  max-width: 850px;
  width: fit-content !important;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}
.references-dialog ::v-deep .el-dialog__header {
  padding: 18px 24px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  border-bottom: none;
}
.references-dialog-title {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  font-family: var(--font-family-fangsong);
  letter-spacing: 2px;
}
.references-dialog-title i { 
  color: #fff; 
  font-size: 22px;
}
.references-dialog ::v-deep .el-dialog__body {
  padding: 0;
  max-height: 70vh;
  overflow-y: auto;
  background: #ffffff;
}
.references-dialog-body { 
  padding: 20px 24px 24px;
  min-width: 450px;
  max-width: 800px;
}
/* 弹窗内的引用项 */
.reference-item-dialog {
  margin-bottom: 20px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}
.reference-item-dialog:last-child {
  margin-bottom: 0;
}
.reference-item-header-dialog {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 2px solid #e5e7eb;
}
.reference-num-dialog {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}
.reference-source-dialog {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  line-height: 1.6;
  font-family: var(--font-family-fangsong);
}
.reference-item-content-dialog {
  padding: 16px 20px;
  background: #f9fafb;
  border-radius: 8px;
  font-size: 15px;
  color: #374151;
  line-height: 2;
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
  font-family: var(--font-family-fangsong);
  text-align: justify;
  letter-spacing: 0.5px;
  max-width: 100%;
  box-sizing: border-box;
}
/* 弹窗滚动条 */
.references-dialog ::v-deep .el-dialog__body::-webkit-scrollbar {
  width: 10px;
}
.references-dialog ::v-deep .el-dialog__body::-webkit-scrollbar-track {
  background: #f8fafb;
}
.references-dialog ::v-deep .el-dialog__body::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 5px;
}
.references-dialog ::v-deep .el-dialog__body::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}
/* 响应式 */
@media (max-width: 900px) {
  .references-dialog ::v-deep .el-dialog {
    min-width: 400px;
    max-width: 90vw;
  }
  .references-dialog-body {
    min-width: 350px;
    max-width: calc(90vw - 48px);
  }
}
@media (max-width: 768px) {
  .references-dialog ::v-deep .el-dialog {
    min-width: 300px;
    max-width: 95vw;
  }
  .references-dialog-body {
    min-width: 250px;
    max-width: calc(95vw - 48px);
    padding: 16px;
  }
  .reference-item-content-dialog {
    font-size: 14px;
    padding: 14px 16px;
    line-height: 1.8;
  }
}
@media (max-width: 480px) {
  .references-dialog ::v-deep .el-dialog {
    min-width: 280px;
    max-width: 98vw;
  }
  .references-dialog-body {
    min-width: 230px;
    max-width: calc(98vw - 40px);
    padding: 12px;
  }
  .reference-item-content-dialog {
    font-size: 13px;
    padding: 12px 14px;
  }
}
</style>

